﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.IO;

namespace BrokerBase.Lib.Client
{
    public class RegistrantInfo
    {
        public static RegistrantInfo Parse(byte[] data)
        {
            try
            {

                RegistrantInfo info = new RegistrantInfo();

                string xml = Encoding.Unicode.GetString(data);

                TextReader reader = new StringReader(xml);

                XElement element = XElement.Load(reader);

                info.UserName = element.Element("UserName").Value;
                info.PresenterName = element.Element("PresenterName").Value;
                info.LicenseCode = element.Element("LicenseCode").Value;
                info.EMail = element.Element("EMail").Value;

                return info;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public XElement GetXml()
        {

            XElement userName = new XElement("UserName", UserName);

            XElement presenterName = new XElement("PresenterName", PresenterName);

            XElement licenseCode = new XElement("LicenseCode", LicenseCode);

            XElement email = new XElement("EMail", EMail);

            XElement root = new XElement("RegistrantInfo", userName, presenterName, licenseCode,email);

            return root;
        }

        public byte[] GetData()
        {
            XElement xml = GetXml();

            string text = xml.ToString();

            byte[] data = Encoding.Unicode.GetBytes(text);

            return data;

        }

        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName { get; set; }
        /// <summary>
        /// 推荐人名
        /// </summary>
        public string PresenterName { get; set; }
        /// <summary>
        /// 产品序列号
        /// </summary>
        public string LicenseCode { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string EMail { get; set; }
    }
}
